﻿using AutoMapper;
using BestTrader.Cms.Models;
using BestTrader.Cms.RmmfSoftServices.Models;
using BestTrader.Cms.ViewModels;
using System;
using System.Collections.Generic;

namespace BestTrader.Cms.Admin.Profiles
{
    /// <summary>
    /// 返佣记录转换规则
    /// </summary>
    public class AgentToRmmfCustomerResolver: CustomerResolver<Manager> //: ITypeConverter<Manager, CustomerInput>
    {
        //public RebateRecordExcelModel Convert(RebateRecord src, RebateRecordExcelModel dest, ResolutionContext context)
        //{
        //    .ForMember(source => source.LoginName, desc => desc.MapFrom(s => s.UserName))
        //        //.ForMember(source => source.Password, desc => desc.MapFrom(s => s.Password))
        //        .ForMember(source => source.RealName, desc => desc.MapFrom(s => s.RealName))
        //        .ForMember(source => source.Telephone, desc => desc.NullSubstitute(""))
        //        .ForMember(source => source.Email, desc => desc.NullSubstitute(""))
        //        .ForMember(source => source.DefaultLanguage, desc => desc.NullSubstitute(0))
        //        .ForMember(source => source.CreateDate, desc => desc.NullSubstitute(DateTime.Now))
        //        .ForMember(source => source.IsLockedOut, desc => desc.NullSubstitute(false))
        //        .ForMember(source => source.LastLockoutDate, desc => desc.NullSubstitute(DateTime.Now))
        //        .ForMember(source => source.SecEmail, desc => desc.NullSubstitute(""))
        //        .ForMember(source => source.UserTypeID, desc => desc.NullSubstitute(1))
        //        .ForMember(source => source.First_Name, desc => desc.MapFrom(s => s.RealName))
        //        .ForMember(source => source.Last_Name, desc => desc.MapFrom(s => s.RealName))
        //        .ForMember(source => source.Postal_Code, desc => desc.NullSubstitute(""))
        //        .ForMember(source => source.Mobile_Phone, desc => desc.MapFrom(s => s.Mobile))
        //        .ForMember(source => source.Identity_Type, desc => desc.NullSubstitute(0))
        //        .ForMember(source => source.Identity_Number, desc => desc.MapFrom(s => s.CardId))
        //        .ForMember(source => source.Current_Trading_Status, desc => desc.NullSubstitute(1))
        //        .ForMember(source => source.Gender, desc => desc.NullSubstitute(2))
        //        .ForMember(source => source.Payee_Name, desc => desc.MapFrom(s => s.BankType))
        //        .ForMember(source => source.Bank_Account, desc => desc.MapFrom(s => s.BankCard))
        //        //.ForMember(source => source.RoleID, desc => desc.MapFrom(s => s.UserName))
        //        //.ForMember(source => source.FirmStructureID, desc => desc.MapFrom(s => s.UserName))
        //        .ForMember(source => source.Client_Type, desc => desc.NullSubstitute(0))
        //}

        public override CustomerInput Convert(Manager source, CustomerInput destination, ResolutionContext context)
        {
            var result = new CustomerInput() {
                LoginName = source.UserName,
                RealName = source.RealName,
                Telephone = "",
                Email = "",
                DefaultLanguage = 0,
                CreateDate = DateTime.Now,
                IsLockedOut = false,
                LastLockoutDate = DateTime.Now,
                SecEmail = "",
                UserTypeID = 1,
                First_Name = source.RealName,
                Last_Name = source.RealName,
                Postal_Code = "",
                Identity_Type = 0,
                Current_Trading_Status = 1,
                Gender = 2,
                Payee_Name = source.BankType,
                //Bank_Account = source.BankCard,
                //Mobile_Phone = source.Mobile,
                //Identity_Number = source.CardId,
                Client_Type = "0"
            };
            result.Email = GetRandomEmail();
            result.Bank_Account = GetRandomBankAccount();
            result.Mobile_Phone = GetRandomPhone();
            result.Identity_Number = GetRandomCardId();

            result.Password = source.Password;
            //result.RealName = source.RealName;
            //result.RoleID = source.RoleID;
            //result.FirmStructureID = source.FirmStructureID;
            

            return result;
        }
    }
}
